﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class ModifyInfo : BaseCheckPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["MerchantId"] != null)
                {
                    int merchantId = int.Parse(Session["MerchantId"].ToString());
                    NxMerchant nxMerchant = ServiceLocator.IMerchantService.GetNxMerchant(merchantId);
                    if (nxMerchant != null)
                    {
                        lbCompanyName.Text = nxMerchant.CompanyName;
                        txtCompanAddress.Text = nxMerchant.CompanyAddress;
                        txtPostalCode.Text = nxMerchant.PostalCode;
                        txtLinkMan.Text = nxMerchant.LinkMan;
                        txtTelephone.Text = nxMerchant.Telephone;
                        txtEmail.Text = nxMerchant.Email;
                        txtCompanyProfile.Text = nxMerchant.CompanyProfile;
                    }
                }
                else
                {
                    Response.Redirect("Login.aspx");
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            NxMerchant nxMerchant = ServiceLocator.IMerchantService.GetNxMerchant(int.Parse(Session["MerchantId"].ToString()));
            if (nxMerchant != null)
            {
                nxMerchant.CompanyAddress = txtCompanAddress.Text.Trim();
                nxMerchant.PostalCode = txtPostalCode.Text.Trim();
                nxMerchant.LinkMan = txtLinkMan.Text.Trim();
                nxMerchant.Telephone = txtTelephone.Text.Trim();
                nxMerchant.Email = txtEmail.Text;
                nxMerchant.CompanyProfile = txtCompanyProfile.Text.Trim();

                if (ServiceLocator.IMerchantService.UpdateNxMerchant(nxMerchant))
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "SAVE_SUCCESSFUL") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "',null)", this.Page);
                }
                else
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "SAVE_ERROR") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "',null)", this.Page);
                }
                
            }
        }
    }
}
